import Sequelize from 'sequelize'
import config from '@/config/index'
import initModels from '@/models/init-models'
const dataBase = config.dataBase
/// https://www.sequelize.com.cn/core-concepts/getting-started
const sequelize = new Sequelize(dataBase.database, dataBase.user, dataBase.password, {
    host: dataBase.host,
    dialect: dataBase.dialect,
    pool: dataBase.pool,
    define: {
        hooks: {
            afterFind(instance, options) {
                console.log('===============afterFind');
            },
        },
    }
});

sequelize
    .authenticate()
    .then(function () {
        console.log('数据库连接成功');
    })
    .catch(function (err) {
        console.error('数据库连接失败:', err);
    });
// function getInstance() {
//     let instance = null
//     return function() {
//         instance = instance ? instance : sequelize
//         return instance
//     }
// }
export default initModels(sequelize)